Passed
Push — master ( 1c7bef...238149 )
by lv
04:37 queued 01:57
created

statistics.js ➔ ???   A

Complexity

Conditions 5
Paths 8

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
dl 0
loc 1
c 0
b 0
f 0
nc 8
rs 9.3333
nop 0
1
const Constant = require('../../libraries/constant')
0 ignored issues
show
Unused Code introduced by
The constant Constant seems to be never used. Consider removing it.
Loading history...
2
const Moment = require('moment')
3
const Redis = require('../../../config/db').redis
4
const ModelStatisticsStore = require('../../../app/model/mist/statisticsStore')
5
6
var INSERT_PER_TIMES = 1000
7
8
var statistics = async function () {
0 ignored issues
show
Bug introduced by
The variable async seems to be never declared. If this is a global, consider adding a /** global: async */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
9
    let accessDate = Moment().subtract(1, 'days').format('YYYY-MM-DD')
10
    let statisticsDay = Moment().subtract(1, 'days').format('YYYYMMDD')
11
    // let accessDate = Moment().format('YYYY-MM-DD')
12
    // let statisticsDay = Moment().format('YYYYMMDD')
13
    let uvCachePrefix = 'MIST:ST_UV:DATE:' + statisticsDay + ':STORE_ID:'
14
    let pvCacheKey = 'MIST:ST_PV:DATE:' + statisticsDay
15
16
    // 根据storeID前缀 1-9 
17
    let keywords
18
    let uvKeys
19
20
    // insert update data
21
    let insertData = []
22
23
    for (let index = 1; index < 10; index++) {
24
        keywords = uvCachePrefix + index.toString() + '*'
25
        uvKeys = await Redis.keys(keywords)
0 ignored issues
show
Bug introduced by
The variable await seems to be never declared. If this is a global, consider adding a /** global: await */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
26
        for (let i = 0; i < uvKeys.length; i++) {
27
            element = uvKeys[i]
0 ignored issues
show
Bug introduced by
The variable element seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.element.
Loading history...
28
            let storeId = element.replace(uvCachePrefix, '')
29
30
            let tmpUv = await Redis.bitcount(element)
31
            let tmpPv = await Redis.hget(pvCacheKey, storeId)
32
33
            let tmp = {
34
                store_id: storeId,
35
                access_date: accessDate,
36
                pv: tmpPv,
37
                uv: tmpUv,
38
            }
39
            // console.log(tmp)
40
            // console.log('---------------------------')
41
42
            insertData.push(tmp)
43
            // 每1000条插入一次
44
            if (insertData.length >= INSERT_PER_TIMES) {
45
                console.log('---- insert DB ---- count: ' + insertData.length)
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
46
                ModelStatisticsStore.add(insertData)
47
                insertData.length = 0
48
            }
49
            
50
        }
51
    }
52
53
    if (insertData.length > 0) {
54
        console.log('---- last insert DB ---- count: ' + insertData.length)
55
        await ModelStatisticsStore.add(insertData)
56
    }
57
58
    // update total
59
    await ModelStatisticsStore.updateStatisticsTotal(accessDate)
60
    console.log('ok statistics.js ' + Moment().format('YYYYMMDD HH:mm:ss'))
61
}
62
63
module.exports = statistics